package com.thinkgem.jeesite.common.persistence;

/**
 * Created by aulbrother on 2015/11/23.
 */
public class Result{
    public static final String SUCCESS="0001";
    public static final String SUCCESS_MSG = "成功";
    public static final String FAILURE="0002";

    // 网络连接错误
    public static final String CONNECTION = "500";
    public static final String CONNECTION_ERROR = "connection error";

    private String code;
    private String msg;
    private Object data;

    public Result(){
    }
    public Result(String msg){
        this.code = SUCCESS;
        this.msg = msg;
        this.data = null;
    }

    public Result(String code, String msg, Object data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result error(String msg){
        return new Result(FAILURE, msg, null);
    }

    public static Result success(String msg){
        return new Result(SUCCESS, msg, null);
    }

    public boolean success(){
        return SUCCESS.equals(this.code);
    }
    public boolean fail(){
        return !success();
    }

    public String getCode(){
        return code;
    }

    public void setCode(String code){
        this.code = code;
    }

    public String getMsg(){
        return msg;
    }

    public void setMsg(String msg){
        this.msg = msg;
    }

    public Object getData(){
        return data;
    }

    public void setData(Object data){
        this.data = data;
    }
}
